#!/usr/bin/env python

"""
docstring
"""

__author__ = 'rx.wen218@gmail.com'

import unittest
from core import sync_task
from core.post import Post

class SyncTaskTest(unittest.TestCase):
    def setUp(self):
        pass

    def testGetPostsToAdd(self):
        src_posts = [
                Post(title = 'title1', content='content1'),
                Post(title = 'title2', content='content2'),
                Post(title = 'title3', content='content3'),
                Post(title = 'title4', content='content4'),
                Post(title = 'title5', content='content5'),
                ]
        dst_posts = []
        st = sync_task.SyncTask(None, None)
        posts_to_add = []
        posts_to_update = []
        st._SyncTask__GetDiffPosts(src_posts, dst_posts, posts_to_add, posts_to_update)
        self.assertEqual(len(src_posts), len(posts_to_add))
        self.assertEqual(0, len(posts_to_update))

        dst_posts.append(src_posts[0])
        posts_to_add = []
        posts_to_update = []
        st._SyncTask__GetDiffPosts(src_posts, dst_posts, posts_to_add, posts_to_update)
        self.assertEqual(len(src_posts)-1, len(posts_to_add))
        self.assertEqual(0, len(posts_to_update))

        dst_posts = src_posts
        posts_to_add = []
        posts_to_update = []
        st._SyncTask__GetDiffPosts(src_posts, dst_posts, posts_to_add, posts_to_update)
        self.assertEqual(0, len(posts_to_add))
        self.assertEqual(0, len(posts_to_update))

    def testGetPostsToUpdate(self):
        src_posts = [
                Post(title = 'title1', content='content1'),
                Post(title = 'title2', content='content2'),
                Post(title = 'title3', content='content3'),
                Post(title = 'title4', content='content4'),
                Post(title = 'title5', content='content5')
                ]
        dst_posts = [
                Post(title = 'title1', content='contenta'),
                Post(title = 'title2', content='contentb'),
                Post(title = 'title3', content='content3'),
                Post(title = 'title4', content='content4'),
                Post(title = 'title5', content='content5')
                ]
        st = sync_task.SyncTask(None, None)
        posts_to_add = []
        posts_to_update = []
        st._SyncTask__GetDiffPosts(src_posts, dst_posts, posts_to_add, posts_to_update)
        self.assertEqual(0, len(posts_to_add))
        self.assertEqual(2, len(posts_to_update))

if __name__ == '__main__':
    unittest.main()
